import Scene from "../Scene";

const { ccclass, property } = cc._decorator;

@ccclass
export default class SceneBase extends Scene {

    @property(cc.Node)
    btnGetSystemInfo: cc.Node = null;

    @property(cc.Node)
    btnGetLaunchOptionsSync: cc.Node = null;

    @property(cc.Node)
    btnExit: cc.Node = null;

    @property(cc.Node)
    btnGC: cc.Node = null;

    @property(cc.Node)
    btnLoadSubpackage: cc.Node = null;

    protected onEnable(): void {
        super.onEnable();
        this.btnGetSystemInfo.on('click', this.onGetSystemInfo, this);
        this.btnGetLaunchOptionsSync.on('click', this.onGetLaunchOptionsSync, this);
        this.btnExit.on('click', this.onExit, this);
        this.btnGC.on('click', this.onGC, this);
        this.btnLoadSubpackage.on('click', this.onLoadSubpackage, this);
    }

    protected onDisable(): void {
        this.btnGetSystemInfo.off('click', this.onGetSystemInfo, this);
        this.btnGetLaunchOptionsSync.off('click', this.onGetLaunchOptionsSync, this);
        this.btnExit.off('click', this.onExit, this);
        this.btnGC.off('click', this.onGC, this);
        this.btnLoadSubpackage.off('click', this.onLoadSubpackage, this);
        super.onDisable();
    }

    //=====================================================================
    private onGetSystemInfo(): void {
        wx.getSystemInfo({
            success(res) {
                console.log("getSystemInfo: ");
                console.log(res);
            },
            fail() {
                wx.showToast({
                    title: 'getSystemInfo failed',
                    icon: 'none',
                    duration: 2000
                });
            }
        })
    }

    private onGetLaunchOptionsSync(): void {
        let options = wx.getLaunchOptionsSync();
        console.log("getLaunchOptionsSync: ");
        console.log(options);
        if (options && options.referrerInfo && options.referrerInfo.appId) {
        }
    }

    private onExit(): void {
        wx.exitMiniProgram({
            success() {
                console.log("exitMiniProgram: ");
            },
            fail() {
                wx.showToast({
                    title: 'exitMiniProgram failed',
                    icon: 'none',
                    duration: 2000
                });
            }
        });
    }

    private onGC(): void {
        wx.triggerGC();
        console.log("triggerGC");
    }

    private onLoadSubpackage(): void {
        console.log("onLoadSubpackage");
    }
}
